﻿if (typeof Pui == 'undefined' || !Pui) {
    (function ($) {
        var Pui = window.Pui = {
            init: function () {
                baseurl = 'http://video.pomoho.com/do';
                _user = {
                    uid: 0,
                    nick: '',
                    spacename: '',
                    newmsg: 0
                };
                _is_login = false;
                document.write('<style type="text/css">.is_login{display:none}</style>');
                var n = this.cookie('LoginInfo');
                if (n) {
                    var arr = n.split('$***$');
                    _user = {
                        uid: arr[0].replace('LoginInfo=', ''),
                        nick: arr[1],
                        spacename: arr[2],
                        username: arr[3],
                        newmsg: 0
                    };
                    _is_login = true;
                    if (Pui.cookie('NewMsgCount' + _user.uid)) {
                        _user.newmsg = Pui.cookie('NewMsgCount' + _user.uid);
                        msg = 'unread';
                    } else {
                        msg = (_user.newmsg == 0) ? 'empty' : 'unread';
                    }
                }
            },
            submitF: function (e) {
                var event = window.event || e;
                if (event.keyCode == 13) $("#btnlog").click();
            },
            EXC: function (e) {
                var event = window.event || e;
                if (event.keyCode == 27) Pui.header.closeDiv();
            },
            cookie: function (name, value, options) {
                if (typeof (value) != 'undefined') {
                    options = options || {};
                    if (value === null) {
                        value = '';
                        options.expires = -1;
                    }
                    var expires = '';
                    if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
                        var date;
                        if (typeof options.expires == 'number') {
                            date = new Date();
                            date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
                        } else {
                            date = options.expires;
                        }
                        expires = '; expires=' + date.toUTCString();
                    }
                    var path = options.path ? '; path=' + options.path : '';
                    var domain = options.domain ? '; domain=' + options.domain : '';
                    var secure = options.secure ? '; secure' : '';
                    document.cookie = [name, '=', name + '=' + value, expires, path, domain, secure].join('');
                } else {
                    var cookieValue = null;
                    if (document.cookie && document.cookie != '') {
                        var cookies = document.cookie.split(';');
                        for (var i = 0; i < cookies.length; i++) {
                            var cookie = jQuery.trim(cookies[i]);
                            if (cookie.substring(0, name.length + 1) == (name + '=')) {
                                cookieValue = unescape(cookie.substring(name.length + 1));
                                break;
                            }
                        }
                    }
                    return cookieValue;
                }
            },
            addEvent: function (target, eventType, functionRef, capture) {
                if (typeof target.addEventListener != 'undefined') {
                    target.addEventListener(eventType, functionRef, capture);
                } else if (typeof target.attachEvent != "undefined") {
                    target.attachEvent("on" + eventType, functionRef);
                }
            },
            callback: function (msg) {
                alert(msg);
            },
            initManage: function (id) {
                if (typeof (id) != 'undefined' && _user.uid != parseInt(id)) document.write('<style type="text/css">.is_login { display:none; }</style>');
                if (typeof (GM) != 'undefined') {
                    GM(_space_user.advid);
                }
                if (typeof (_space_user.username) != 'undefined' && typeof (_user.username) != 'undefined' && _space_user.username == _user.username) {
                    document.write('<style type="text/css">.is_login{display:inline-block}</style>');
                }
            },
            ajaxLoad: function (type, url, data, dataType, d, fun) {
                $.ajax({
                    type: type,
                    url: url,
                    data: data,
                    dataType: dataType,
                    beforeSend: function () {
                        if (typeof (d) != 'undefined' && d.length > 0) $(d).show();
                    },
                    complete: function () {
                        if (typeof (d) != 'undefined' && d.length > 0) $(d).hide();
                    },
                    success: function (data) {
                        _getDATA = data;
                        fun.call(this);
                    }
                });
            },
            Resize: function (im, nWidth, nHeight) {
                var obj = im || document.getElementById(im);
                var w, h, p1, p2;
                p1 = nWidth / nHeight;
                p2 = obj.width / obj.height;
                w = 0;
                h = 0;
                if (p1 < p2) {
                    w = nWidth;
                    h = nWidth * (1 / p2);
                } else {
                    if (obj.width < nWidth && obj.height < nHeight) {
                        w = obj.width;
                        h = obj.height;
                    } else {
                        h = nHeight;
                        w = nHeight * p2;
                    }
                }
                obj.width = w;
                obj.height = h;
                obj.style.marginTop = (nHeight - h) / 2 + 'px';
            },
            autoThumb: function (path, w, h) {
                var _self = this;
                $(path).each(function (i) {
                    var preldimg = new Image();
                    preldimg.onload = function () {
                        setTimeout(function () {
                            _self.Resize($(path)[i], w, h);
                            preldimg = null;
                        },
                        50);
                    }
                    preldimg.src = $(path)[i].src;
                });
            },
            ui: function () {
                return {
                    copy: function (text, msg) {
                        if ($.browser.msie) {
                            window.clipboardData.setData("Text", text);
                        } else {
                            if (!document.getElementById('flashcopier')) {
                                $('<div id="flashcopier"></div>').appendTo('body');
                            }
                            $('#flashcopier').html('<embed src="http://static.pomoho.com/scriptures/clipboard.swf" FlashVars="clipboard=' + text + '" width="0" height="0" style="position:absolute; top:-2000px;" type="application/x-shockwave-flash"></embed>');
                        }
                        if (msg) {
                            alert(msg);
                        }
                    },
                    bookmark: function (title, url) {
                        if ($.browser.msie) {
                            window.external.AddFavorite(url, title);
                        } else if ($.browser.mozilla) {
                            window.sidebar.addPanel(title, url, '');
                        }
                    },
                    setHome: function (url) {
                        try {
                            document.body.style.behavior = 'url(#default#homepage)';
                            document.body.setHomePage(url);
                        } catch (e) {
                            if (window.netscape) {
                                try {
                                    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
                                    var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
                                    prefs.setCharPref('browser.startup.homepage', 'http://www.pomoho.com');
                                } catch (e) {
                                    alert("不好意思，此操作被浏览器拒绝……\n请在浏览器地址栏输入“about:config”并回车\n然后将[signed.applets.codebase_principal_support]设置为'true'\n或者直接在选项中设置首页。多谢支持爆米花的产品。");
                                }
                            }
                        }
                    },
                    pos: function () {
                        return {
                            elementTop: function (element) {
                                var y = 0;
                                for (var e = element; e; e = e.offsetParent) y += e.offsetTop;
                                for (e = element.parentNode; e && e != document.body; e = e.parentNode) if (e.scrollTop) y -= e.scrollTop;
                                return y;
                            }
                        }
                    } (),
                    gettime: function () {
                        var time = new Date();
                        var t_year = ($.browser.msie) ? time.getYear() : String(time).split(" ")[3];
                        var t_time = ($.browser.msie) ? String(time).split(" ")[3].substr(0, 5) : String(time).split(" ")[4].substr(0, 5);
                        var f_time = t_year + "-" + parseInt(time.getMonth() + 1) + "-" + time.getDate() + " " + t_time;
                        return f_time;
                    },
                    setServerTime: function (time) {
                        _servertime = time;
                    },
                    loadServerTime: function () {
                        Pui.loadScript("http://www.pomoho.com/do/time/echo_second.aspx");
                    },
                    tabTurn: function (a, b, c) {
                        $(a).click(function () {
                            var t = $(this);
                            var o = $(a).index(t[0]);
                            $(a).removeClass(c);
                            $(b).hide();
                            t.addClass(c);
                            $(b).eq(o).show();
                            return false;
                        });
                    },
                    keyCode: function (e, callback) {
                        var event = window.event || e;
                        if (event.keyCode == 13) {
                            callback();
                        }
                    }
                }
            } (),
            loadScript: function (url, options) {
                var setting = {
                    random: true
                };
                if (options) {
                    $.extend(setting, options);
                }
                var f = document.createElement('script');
                f.type = 'text/javascript';
                var d = new Date();
                if (setting.random) {
                    if (url.match(/.*\?./)) {
                        url = url + '&random=' + d.getTime() + parseInt(Math.random() * 10000);
                    } else {
                        url = url + '?random=' + d.getTime() + parseInt(Math.random() * 10000);
                    }
                }
                f.src = url;
                $('head')[0].appendChild(f);
            }
        }
        Pui.init();
    })(jQuery);
}
Pui.header = {
    init: function (json) {
        _user = {
            uid: 0,
            nick: 'onemax',
            spacename: '',
            newmsg: 0
        };
        _is_login = false;
        var n = Pui.cookie('LoginInfo');
        if (n) {
            var arr = n.split('$***$');
            _user = {
                uid: arr[0].replace('LoginInfo=', ''),
                nick: arr[1],
                spacename: arr[2],
                newmsg: 0,
                spaceurl: arr[3]
            };
            _is_login = true;
        } else {
            _is_login = false;
        };
        if ('undefined' == typeof (json) || json) {
            if (_is_login) {
                this.islogin();
            } else {
                this.unlogin();
            }
        }
    },
    logDiv: function (sType, sTarget, sUrl, callback) {
        var str = '';
        if ($.browser.msie && String($('body').attr('id')) == 'B-Upload') {
            str += '';
        } else {
            /*if ($.browser.msie) {
            str += '<iframe id="zhezhao"></iframe>';
            } else {
            str += '<div id="zhezhao"></div>';
            }*/
            str += '<div id="zhezhao"></div>';
        }
        str += ' <div id="Prompt" class="prompt">';
        str += '    <div class="k log_v">';
        str += '      <div class="meat">';
        str += '        <div class="close"><a title="关闭"></a></div>';
        str += '        <h3></h3>';
        str += '        <p class="p2">您的帐号：';
        str += '          <input id="uidName" type="text" onkeypress="Pui.submitF(event)" />';
        str += '        </p>';
        str += '        <p class="p2">登录密码：';
        str += '          <input id="uidPwd" type="password" onkeypress="Pui.submitF(event)" />';
        str += '          <a href="http://b.pomoho.com/ui/findpassword.aspx" target="_blank">忘记密码</a></p>';
        str += '        <p class="pbt">';
        str += '          <input id="btnlog" class="log" type="submit" value="登录" />';
        str += '          <input id="reg" class="log" type="button" value="注册" />';
        str += '        </p>';
        str += '      </div>';
        str += '    </div>';
        str += '  </div>';
        $("body").prepend(str);
        if ($.browser.msie && String($('body').attr('id')) == 'B-Upload') {
            Pra.ui.overlay();
        } else {
            /*if ($.browser.msie) {
            var cw = window.frames['zhezhao'];
            cw.document.open();
            cw.document.write('<style type="text/css">body{background:#000;}</style>');
            cw.document.close();
            }*/
        }
        $("#Prompt .close a").bind("click", Pui.header.closeDiv);
        $("#btnlog").click(function () {
            Pui.header.login(sType, sTarget, sUrl, callback);
        });
        $("#reg").click(function () {
            window.open('http://www.baomihua.com/ui/reg.aspx?cuyingshi');
        });
    },
    showLogDiv: function (sType, sTarget, sUrl, callback) {
        if (String($('body').attr('id')) == 'B-Upload') {
            this.logDiv(sType, sTarget, sUrl, callback);
        } else if (!$("#Prompt").length) {
            this.logDiv(sType, sTarget, sUrl, callback);
        }
        var doc = document;
        var docElement = doc.documentElement;
        var sHeight = docElement.clientHeight;
        var dH = docElement.scrollHeight > sHeight ? docElement.scrollHeight : sHeight;
        var scH = docElement.scrollTop >= 0 ? (docElement.scrollTop + sHeight / 2) : sHeight;
        var h = scH - $("#Prompt").height() / 2;
        var w = docElement.clientWidth / 2 - $("#Prompt").width() / 2;
        $("#zhezhao").height(dH).show();
        $("#Prompt").css({
            top: h,
            left: w
        });
    },
    loginfo: function (sType, sTarget, sUrl, callback) {
        this.showLogDiv(sType, sTarget, sUrl, callback);
        $("#Prompt").show();
        $("#Prompt .k")[0].className = "k log_v";
        $('#uidName').focus();
        if (document.attachEvent) {
            document.attachEvent('onkeyup', Pui.EXC);
        } else {
            document.addEventListener('keyup', Pui.EXC, false)
        }
    },
    loginfo2: function (callback, sType, sTarget, sUrl) {
        this.loginfo(sType, sTarget, sUrl, callback);
    },
    loginfo2_callback: function (json) {
        window.location.href = "http://b.pomoho.com/manage/index.aspx";
    },
    unlogin: function () {
        var str = '';
        str += '<div class="row" id="topNav">';
        if (document.location.host.toString().indexOf('cu.365dianying.com') > -1) {
            str += '<a title="登录" href="javascript:Pui.header.loginfo2()">登录</a>';
        } else {
            str += '<a title="登录" href="javascript:Pui.header.loginfo2(Pui.header.loginfo2_callback)">登录</a>';
        }
        str += '<a title="注册" href="http://www.baomihua.com/ui/reg.aspx?cuyingshi" target="_blank">注册</a>';
        if (document.location.host.toString().indexOf('home.pomoho.com') != -1) {
            str += '<a target="_blank" href="http://bbs.pomoho.com">论坛</a>';
        } else {
            str += '<a href="http://www.pomoho.com/upload/" target="_blank" title="上传视频">上传视频</a>';
        }
        str += '</div>';
        $("#top_Nav #L").html(str);
    },
    islogin: function () {
        var t_time = this.localTime();
        var str = '';
        str += '<div class="row" id="topNav">';
        str += '<span class="welcome"><span class="time">' + t_time + '，</span><a class="user" target="_blank" href="http://home.pomoho.com/' + _user.spaceurl + '.shtml" title="' + _user.nick + '" >' + Pui.header.SetString(_user.nick, 10) + '</a></span>';
        str += '<span class="s"><a class="count" title="你的帐户" href="http://b.pomoho.com/manage/index.aspx" target="_blank" >帐户</a>';
        str += '   <div class="dbd s3">';
        str += '     <ul>';
        str += '       <li><a class="d_item" title="我的视频" href="http://b.pomoho.com/manage/managevideo.aspx" target="_blank" >我的视频</a></li>';
        str += '       <li><a class="d_item" title="我的订阅" href="http://b.pomoho.com/manage/subscribevblog.aspx" target="_blank" >我的订阅</a></li>';
        str += '       <li><a class="d_item" title="我的收藏" href="http://b.pomoho.com/manage/managevideo.aspx?type=favs" target="_blank" >我的收藏</a></li>';
        str += '       <li><a class="d_item" title="我的相册" href="http://b.pomoho.com/manage/managealbum.aspx" target="_blank" >我的相册</a></li>';
        str += '     </ul>';
        str += '     <div class="m1"><a title="更多管理" href="http://b.pomoho.com/manage/index.aspx" target="_blank" >更多..&nbsp;&nbsp;</a></div>';
        str += '   </div>';
        str += ' </span>';
        if (document.location.host.toString().indexOf('home.pomoho.com') != -1) {
            str += '<a target="_blank" href="http://bbs.pomoho.com">论坛</a>';
        } else {
            str += ' <span class="s"><a class="msg" title="你的消息" href="http://b.pomoho.com/manage/messagelist.aspx?type=1" target="_blank" >消息</a><span>(0)</span>';
            str += '   <div class="dbd s2">';
            str += '     <div class="title"><div class="d_video">主题</div><div class="d_author">消息来源</div></div>';
            str += '     <ul>';
            str += '     </ul>';
            str += '     <div class="m"><a title="全部消息" href="http://b.pomoho.com/manage/messagelist.aspx?type=1" target="_blank" >全部消息&gt;&gt;</a></div>';
            str += '   </div>';
            str += ' </span>';
            str += '<a href="http://www.pomoho.com/upload/" target="_blank" title="上传视频">上传视频</a>';
        }
        str += ' <a title="退出登录" href="http://b.pomoho.com/ui/logout.aspx?AfterLoginReturnURL=' + window.location + '" >退出</a>';
        str += '</div>';
        $("#L").removeClass().html(str);
        this.SH();
        Pui.loadScript("http://notice.pomoho.com/loadmessage2.0.aspx?v=3");
    },
    SetString: function (str, len) {
        var strlen = 0;
        var s = "";
        for (var i = 0; i < str.length; i++) {
            if (str.charCodeAt(i) > 128) strlen += 2;
            else strlen++;
            s += str.charAt(i);
            if (strlen >= len) return s;
        }
        return s;
    },
    SH: function () {
        var tim;
        $("#top_Nav #L .s").hover(function () {
            $(this).siblings().find(".dbd").hide();
            $(this).find(".dbd").show();
            clearTimeout(tim);
        },
        function () {
            tim = setTimeout(overDiv, 500);
            function overDiv() {
                $(this).find(".dbd").slideUp();
            }
        });
    },
    localTime: function () {
        var time = new Date();
        var hour = time.getHours();
        var t_time = ($.browser.msie) ? String(time).split(" ")[3].substr(0, 5) : String(time).split(" ")[4].substr(0, 5);
        switch (hour) {
            case 0:
            case 1:
            case 2:
            case 3:
            case 4:
            case 5:
            case 6:
            case 7:
                t_time = '早上好';
                break;
            case 8:
            case 9:
            case 10:
            case 11:
                t_time = '上午好';
                break;
            case 12:
                t_time = '中午好';
                break;
            case 13:
            case 14:
            case 15:
            case 16:
            case 17:
                t_time = '下午好';
                break;
            case 18:
            case 19:
            case 20:
            case 21:
            case 22:
            case 23:
                t_time = '晚上好';
                break;
        }
        return t_time;
    },
    Msginit: function (jsonMsg) {
        var str = '';
        var len = jsonMsg.length;
        if (len <= 1) {
            var str = '<li style="width:100%">您还没有消息</li>';
        } else {
            for (var i = 1; i <= len - 1; i++) {
                var msgtypename;
                switch (jsonMsg[i].msgtype) {
                    case 1:
                        msgtypename = "站内消息";
                        break;
                    case 2:
                        msgtypename = "系统消息";
                        break;
                    case 3:
                        msgtypename = "公告";
                        break;
                }
                str += '<li id="msg' + i + '">';
                if (jsonMsg[i].msgtype != 3) {
                    str += '<div class="d_video"><a title="' + jsonMsg[i].msgtitle + '" href="http://b.pomoho.com/manage/readmessage.aspx?receiveid=' + jsonMsg[i].msgid + '&rettype=1" target="_blank" >' + jsonMsg[i].msgtitle + '</a></div>';
                } else {
                    str += '<div class="d_video"><a title="' + jsonMsg[i].msgtitle + '" href="http://b.pomoho.com/manage/readmessage.aspx?bulletinid=' + jsonMsg[i].msgid + '&rettype=1" target="_blank" >' + jsonMsg[i].msgtitle + '</a></div>';
                }
                str += '<div class="d_author">' + msgtypename + '</div>';
                str += '<a class="d_close" title="删除消息" href="javascript:Pui.header.Msgdel(' + jsonMsg[i].msgid + ',' + jsonMsg[i].msgtype + ',' + i + ')" ></a> </li>';
            }
        }
        $("#top_Nav #L .s2 ul").html(str);
        $("#top_Nav #L .s2").parent().find("span").html("(" + jsonMsg[0] + ")");
    },
    Msgdel: function (msgid, msgtype, num) {
        $("#msg" + num).remove();
        var Msgurl = "http://notice.pomoho.com/readmessage.aspx?messageID=" + msgid + "&Userid=" + _user.uid + "&messageType=" + msgtype;
        Pui.loadScript(Msgurl);
        var num = parseInt($("#topNav .s2").parent().find("span").html().substr(1)) - 1;
        if (num <= 0) num = 0;
        $("#topNav .s2").parent().find("span").html("(" + num + ")");
    },
    login: function (sType, sTarget, sUrl, callback) {
        var userName = $.trim($("#uidName").val());
        var pwd = $("#uidPwd").val();
        if (userName == '' || pwd == '') {
            alert("用户名或者密码不能为空");
        } else {
            if (sType || sUrl) {
                Pui.header.ui.logDiagAjax(userName, pwd, sType, sTarget, sUrl, callback);
            } else {
                Pui.header.logAjax(userName, pwd, callback);
            }
        }
    },
    closeDiv: function () {
        if ($.browser.msie && String($('body').attr('id')) == 'B-Upload') {
            Pra.ui.overlay();
        } else if (String($('body').attr('id')) == 'B-Upload') {
            $("#zhezhao").remove();
        } else {
            $("#zhezhao").hide();
        }
        $("#Prompt").hide();
        return false;
    },
    ui: function () {
        return {
            logDiag: function (sType, sTarget, sUrl) {
                if (_is_login) {
                    if (sType == 'new') {
                        window.open(sTarget);
                    } else {
                        window.location.href = sTarget;
                    }
                } else {
                    Pui.header_v2.loginfo(sType, sTarget, sUrl);
                }
            },
            logDiagAjax: function (userName, pwd, sType, sTarget, sUrl) {
                $.ajax({
                    url: sUrl,
                    dataType: "xmlDocument",
                    type: "post",
                    data: "action=http://b.pomoho.com/ui/logindo.aspx&form_name=" + userName + "&form_password=" + pwd + "&type=gamelogin&random=" + Math.random(),
                    error: function () {
                        alert('可能网络问题,登录失败,请重试');
                    },
                    success: function (result) {
                        var userlog = eval(result);
                        switch (parseInt(userlog[0].stat)) {
                            case -1: alert("登录帐号不存在");
                                break;
                            case -2: alert("用户名或者密码错误,请重试");
                                break;
                            case 1:
                                Pui.cookie('UserInfo', userlog[1].UserInfo, {
                                    path: '/',
                                    domain: '.pomoho.com',
                                    expires: 1 / 6
                                });
                                Pui.cookie('LoginInfo', userlog[2].LoginInfo, {
                                    path: '/',
                                    domain: '.pomoho.com',
                                    expires: 1 / 6
                                });
                                Pui.header.init();
                                if (String($('body').attr('id')) == 'B-Upload-1' && (n == true) && (typeof (flag) == 'undefined' || flag == null)) {
                                    Pui.upload.unite('GoTo2');
                                    start_upload($('#file1').val(), $('#uploadForm_Title').val());
                                    return;
                                }
                                if (sType == 'local') {
                                    window.location.href = sTarget;
                                } else if (sType == 'new') {
                                    Pui.header.closeDiv();
                                    window.open(sTarget);
                                }
                                if (typeof (flag) == 'undefined' || flag == null) Pui.header.closeDiv();
                                break;
                            default:
                                alert("系统错误,请重试，错误代码：" + userlog[1].ErrMsg);
                        }
                    }
                });
            }
        }
    },
    logAjax: function (userName, pwd, callback) {
        var urlRoot = window.location.hostname;
        var urlString = window.location.toString().toLowerCase();
        var urlstr;
        if (urlString.indexOf("video.pomoho.com/") == -1) {
            urlstr = "/do/interfaces/sendajaxreq.aspx";
        } else {
            urlstr = "/sendajaxreq.aspx";
        }
        if (urlRoot.indexOf("cu.365dianying.com") > -1) {
            var param = { userName: userName, password: pwd };
            $.ajax({
                type: "get",
                url: "http://www.pomoho.com/api/userapi.asmx/UserLogin",
                data: param,
                dataType: "jsonp",
                jsonp: "jsoncallback",
                timeout: 300000,
                success: function (result) {
                    switch (parseInt(result.Result)) {
                        case -1:
                            alert("登录帐号不存在");
                            break;
                        case -2:
                            alert("用户名或者密码错误,请重试");
                            break;
                        case 1:

                            Pui.cookie('UserInfo', result.UserInfo, {
                                path: '/',
                                // domain: '.365dianying.com',
                                expires: 1 / 6
                            });
                            Pui.cookie('LoginInfo', result.LoginInfo, {
                                path: '/',
                                //  domain: '.365dianying.com',
                                expires: 1 / 6
                            });

                            var httpurl = "http://www.29293.com/logindo.aspx?form_name=" + userName + "&userInfo=" + result.UserInfo + "&loginInfo=" + result.LoginInfo;
                            var _frm = document.createElement("iframe");
                            _frm.style.display = "none";
                            _frm.src = httpurl;
                            document.body.appendChild(_frm);
                            Pui.header.init();
                            Pui.header.closeDiv();
                            break;
                        default:
                            alert("系统错误,请重试...");
                            Pui.header.closeDiv();
                    }

                }
            });
        }
        else {
            $.ajax({
                url: "http://" + urlRoot + urlstr,
                dataType: "xmlDocument",
                type: "post",
                data: "action=http:/" + urlRoot + "/ui/logindo.aspx&form_name=" + userName + "&form_password=" + pwd + "&type=gamelogin&random=" + Math.random(),
                error: function () {
                    alert('可能网络问题,登录失败,请重试!');
                    Pui.header.closeDiv();
                },
                success: function (result) {
                    var userlog = eval(result);
                    switch (parseInt(userlog[0].stat)) {
                        case -1: alert("登录帐号不存在");
                            break;
                        case -2: alert("用户名或者密码错误,请重试");
                            break;
                        case 1:
                            Pui.cookie('UserInfo', userlog[1].UserInfo, {
                                path: '/',
                                domain: '.pomoho.com',
                                expires: 1 / 6
                            });
                            Pui.cookie('LoginInfo', userlog[2].LoginInfo, {
                                path: '/',
                                domain: '.pomoho.com',
                                expires: 1 / 6
                            });
                            var urlString = window.location.toString().toLowerCase();
                            if (urlString.indexOf("pomoho.com/combo") != -1 && (typeof (flag) == 'undefined' || flag == null)) {
                                window.location.reload();
                                return
                            }
                            Pui.header.init();
                            if (String($('body').attr('id')) == 'B-Upload' && document.getElementById("hid_n").value == "true" && (typeof (flag) == 'undefined' || flag == null)) {
                                document.getElementById("FrameUpload").contentWindow.Pui.upload.unite('GoTo2');
                                document.getElementById("FrameUpload").contentWindow.start_upload(document.getElementById("FrameUpload").contentWindow.$('#file1').val(), document.getElementById("FrameUpload").contentWindow.$('#uploadForm_Title').val());
                                if (document.getElementById("FrameUpload").contentWindow.$('#hid_ver').val() == 'family') {
                                    document.getElementById("FrameUpload").contentWindow.$('#Upload_2 .s4').addClass('none');
                                    document.getElementById("FrameUpload").contentWindow.$('#Upload_2 .s5').addClass('none');
                                    $('#Layout_1').height('650px');
                                } else {
                                    $('#Layout_1').height('700px');
                                }
                            }
                            if (typeof (flag) == 'undefined' || flag == null) Pui.header.closeDiv();
                            else if (flag == 1) {
                                Pui.user.haveFriend();
                                flag = null;
                            } else if (flag == 2) {
                                Pui.loadScript("http://www.pomoho.com/do/video/dealajaxdata.aspx?itype=2&imdbid=" + flvid);
                                flag = null;
                                Pui.header.closeDiv();
                            } else if (flag == 3) {
                                f_addfriend(_userid);
                                flag = null;
                                Pui.header.closeDiv();
                            } else if (flag == 4) {
                                flag = null;
                                Pui.header.closeDiv();
                                f_comboInterFace(addPram.otype, addPram.atype, addPram.comboid, _user.uid);
                                Pui.header.closeDiv();
                            } else if (flag == 5) {
                                flag = null;
                                Pui.ReUrl(pathUrl);
                                Pui.header.closeDiv();
                            } else if (flag == 6) {
                                flag = null;
                                Pui.space.commentJudge();
                            }
                            if ('undefined' != typeof (callback)) {
                                callback();
                            }
                            break;
                        default:
                            alert("系统错误,请重试，错误代码：" + userlog[1].ErrMsg);
                            Pui.header.closeDiv();
                    }
                }
            });
        }
    }
}
Pui.msg = {
    init: function (url) {
        this.currPage = 1;
        this.totalPage = 0;
        this.allPage = 0;
        this.xmlPage = 0;
        this.url = url;
        if (_is_login) {
            Pui.loadScript(url);
        }
    },
    jsonMessage: function (json) {
        this.currPage = 1;
        if (!json['show']) return;
        this.totalPage = json['totalPage'];
        if (this.totalPage != 0) {
            if ($('#TT')[0]) {
                $('#TT .login img').attr('src', 'http://static.pomoho.com/themes/site/200708/images/public/msg_unread.png');
                $('#TT .login span').text(this.totalPage);
            } else if ($('#T')[0]) {
                $('#T .msg').html(' <img src="http://static.pomoho.com/themes/site/200708/images/public/msg_unread.png" />(' + this.totalPage + ')');
            }
        }
        this.allPage = json['allPage'];
        this.xmlPage = json['xmlpage'];
        var content = '<div class="content">';
        for (var i = 0; i < json['items'].length; i++) {
            var item = json['items'][i];
            if (i == 0) {
                content += '<div id="msg_' + item['id'] + '" class="' + item['type'] + '">' + item['content'] + '</div>';
            } else {
                content += '<div id="msg_' + item['id'] + '" class="' + item['type'] + '" style="display:none">' + item['content'] + '</div>';
            }
        }
        content += '</div>';
        if (!!document.getElementById('Message')) $('#Message').remove();
        $('<div id="Message"></div>').html(content).prependTo('.body_btm_fix');
        $('<div class="handle"><span class="close"><a href="javascript:Pui.msg.close()" title="关闭窗口">关闭</a></span></div>').appendTo('#Message');
        if (this.totalPage != 1) {
            $('<span class="roll"><a href="javascript:Pui.msg.next();" title="下一条" class="next">下一条</a></span>').prependTo('#Message .handle');
            $('<span class="count">' + this.currPage + '/' + this.totalPage + '</span>').prependTo('#Message .handle');
        } else {
            $('<span class="count" style="margin-right:6px;">' + this.currPage + '/' + this.totalPage + '</span>').prependTo('#Message .handle');
        }
        if (json['more'] == 1) {
            $('<span class="more" style="margin-right:6px;margin-top:4px;"><a href="http://www.pomoho.com/">更多</a></span>').prependTo('#Message .handle');
        }
    },
    prev: function (e) {
        this.currPage--;
        this.show();
    },
    next: function (e) {
        this.currPage++;
        this.show();
    },
    show: function () {
        if (this.allPage > 50 && this.currPage == 51 + this.xmlPage) {
            window.location = "http://www.pomoho.com/";
        }
        $('#Message .content div').hide().eq(this.currPage - 1).show();
        $('#Message .count').html(this.currPage + '/' + this.totalPage);
        if (this.currPage == 1) {
            $('#Message .roll').html('<span class="roll"><a href="javascript:Pui.msg.next();" title="下一条" class="next">下一条</a></span>');
        } else if (this.currPage > 1 && this.currPage < this.totalPage) {
            $('#Message .roll').html('<span class="roll"><a href="javascript:Pui.msg.prev();" title="上一条" class="prev">上一条</a><a href="javascript:Pui.msg.next();" title="下一条" class="next">下一条</a></span>');
        } else if (this.currPage == this.totalPage) {
            $('#Message .roll').html('<span class="roll"><a href="javascript:Pui.msg.prev();" title="上一条" class="prev">上一条</a></span>');
        }
    },
    close: function () {
        $('#Message').slideUp();
        var currTime = new Date().getTime();
        Pui.cookie('NewMsgCount' + _user.uid, this.totalPage, {
            expires: 1,
            domain: 'pomoho.com'
        });
        Pui.loadScript('http://notice.pomoho.com/closemessage.aspx?userid=' + _user.uid);
    },
    readMessageHandler: function (handler) {
        if (handler) {
            if (this.totalPage == 1) {
                $('#Message').fadeOut('slow');
            } else {
                if (typeof (this.url) != 'undefined') Pui.loadScript(this.url);
            }
        }
    },
    friendadd: function (type, friendID, messageID) {
        Pui.loadScript("http://notice.pomoho.com/MessagEven.aspx?type=" + type + "&receiveID=" + friendID + "&messageID=" + messageID);
    },
    InvertCombo: function (type, friendID, messageID, ComboID) {
        Pui.loadScript("http://notice.pomoho.com/MessagEven.aspx?type=" + type + "&receiveID=" + friendID + "&messageID=" + messageID + "&ComboID=" + ComboID);
    }
}
Pui.searching = {
    init: function () {
        Pui.searching.showHotKeywords();
        this.Main();
		Pui.newHeader.init();
        //$('#SearchForm').submit(function () {
            //Pui.searching.DoSearch(this);
            //return false;
        //});
    },
    Main: function () {
        this.SelectEvents();
        this.showMore();
    },
    OnLoad: function () {
        var defalt_val = '搜一下';
        $('#SearchInput').val(defalt_val).focus(function () {
            var val = $(this).val();
            if (val == defalt_val) {
                $(this).val('');
            }
        }).blur(function () {
            var val = $(this).val();
            if (val == '') {
                $(this).val(defalt_val);
            }
        });
    },
    SelectEvents: function () {
        $('body').click(function () {
            if ($('#SelDiag').css('display') != 'none') {
                $('#SelDiag').slideUp('fast');
            }
        });
        $('.btnSel a').click(function () {
            if ($('#SelDiag').css('display') != 'none') {
                $('#SelDiag').slideUp('fast');
            } else {
                $('#SelDiag').slideDown('fast');
            }
            return false;
        });
        $('#SelDiag1').click(function () {
            Pui.searching.SelectDiag('video', $(this));
            this.blur();
            return false;
        });
        $('#SelDiag2').click(function () {
            Pui.searching.SelectDiag('user', $(this));
            this.blur();
            return false;
        });
        $('#SelDiag3').click(function () {
            Pui.searching.SelectDiag('subject', $(this));
            this.blur();
            return false;
        });
    },
    SelectDiag: function (searchType, href) {
        $('#SearchType').val(searchType);
        $('#SelDiag').css('display', 'none');
        $('#Selected').text($(href).text());
        $('#SearchT').focus();
    },
    showMore: function () {
        $('#Menu li:last a').click(function () {
            if ($('.morelist').css('display') != 'none') {
                $('.morelist').css('display', 'none'); ;
                $('#Menu li:last a strong').html('▼');
            } else {
                $('.morelist').css('display', 'block');
                $('#Menu li:last a strong').html('▲');
            }
            return false;
        });
        $('body').click(function () {
            $('.morelist').css('display', 'none');
            $('.morelist').css('display', 'none'); ;
            $('#Menu li:last a strong').html('▼');
        });
    },
    showHotKeywords: function (a) {
        //var hotKeys = a[0].data;
        var hotKeys = new Array('%e8%b5%9b%e5%b0%94%e5%8f%b7',
         '%e5%b9%bf%e5%b7%9e%e5%9c%b0%e9%93%81%e5%85%8d%e8%b4%b9',
         '%e5%8d%b0%e5%b0%bc%e7%81%ab%e5%b1%b1');
        var u = 'http://search.pomoho.com/videosearch.aspx?_keyword=';
        var HotKey = document.createElement('span');
        HotKey.className = 'hot_keywords';
        HotKey = $(HotKey);
        for (var i = 0,
        j = hotKeys.length; i < j; i++) {
            HotKey.append('<a href="' + (u + hotKeys[i]) + '&_f=x0s01" target="_blank">' + decodeURIComponent(hotKeys[i]) + '</a>');
        }
        HotKey.appendTo('.header2 #phead')
    },
    DoSearch: function (o) {
        var val = $(o).find('#SearchInput').val();
        if ($.trim(val) == '' || val == '搜一下') {
            alert('对不起，关键词不能为空，请重新输入');
            $('#SearchInput').focus();
            return false;
        } else {
            var sdi = o.searchDomain;
            var sd = "http://so.baomihua.com";
            if (sdi != undefined && sdi.value != "") {
                sd = sdi.value;
            }
         //   var key = encodeURIComponent(val);
            // var url = sd + "/" + o.SearchType.value + "search.aspx?_keyword=" + key + '&_f=p0s04';
            var key = val;
            var url = sd + "/v/" + key + '_p0s04.html';
            if (document.location.hostname.indexOf("so.baomihua.com") != -1) {
                document.location.href = url;
            } else {
                window.open(url, 'search');
            }
            return false;
        }
    },
    Search: function (val) {
        if (val == '') {
            return false;
        } else {
            var sd = "http://so.baomihua.com";
            var key = encodeURIComponent(val);
            var url = sd + "/videosearch_v2.aspx?_keyword=" + key;
            if (document.location.hostname.indexOf("so.baomihua.com") != -1) {
                document.location.href = url;
            } else {
                window.open(url, 'search');
            }
            return false;
        }
    }
}
Pui.searching.keyWords = {
    keyWords_show: function (k) {
        Pui.addEvent(window, 'load',
        function () {
            Pui.searching.keyWords.keyWords_turn();
        },
        false);
    },
    keyWords_turn: function () {
        var arr_s = keywords.split(',');
        var i = 0,
        l = arr_s.length,
        oSI = $('#SearchInput');
        function g() {
            if (i < l) {
                oSI.val(arr_s[i]).css('color', '#ccc');
                i++;
                t = window.setTimeout(function () {
                    g()
                },
                2000);
            } else {
                i = 0;
                g();
            }
        }
        g();
        oSI.focus(function () {
            window.clearTimeout(t);
            if (oSI.val() == arr_s[i - 1]) {
                oSI.val('');
            }
        }).blur(function () {
            if (oSI.val() == '') {
                g();
            }
        });
    }
}
Pui.searching.Searched = {
    init: function () {
        this.searchover();
    },
    searchover: function () {
        var addrurl = window.location.toString().toLocaleLowerCase();
        if (/_keyword=/.test(addrurl)) {
            searchVal = decodeURIComponent(addrurl.split("_keyword=")[1].split("&")[0]);
            $.getJSON("http://video.baomihua.com/do/interfaces/relatedwords.aspx?jsoncallback=?&key=" + encodeURIComponent(searchVal), function (data) {
                if (data.html != -1) {
                    $("#div_key_related").html(data.html);
                }
            });
            //$.getJSON("http://60.191.101.7/getsearchcusubjectjson.aspx?jsoncallback=?&keyword=" + encodeURIComponent(searchVal), function (data) {
             //   if (data.html != "") {
              //      $("#div_series_cusubject").html(unescape(data.html));
              //  }
          //  });
        }
        else {
            if (addrurl.indexOf('search.pomoho.com/v/') > -1 || addrurl.indexOf('so.baomihua.com/v/') > -1) {
                searchVal = decodeURIComponent(addrurl.split('/v/')[1].split('.html')[0].split('_')[0]);
                $.getJSON("http://video.baomihua.com/do/interfaces/relatedwords.aspx?jsoncallback=?&key=" + encodeURIComponent(searchVal), function (data) {
                    if (data.html != -1) {
                        $("#div_key_related").html(data.html);
                    }
                });
             //   $.getJSON("http://60.191.101.7/getsearchcusubjectjson.aspx?jsoncallback=?&keyword=" + encodeURIComponent(searchVal), function (data) {
              //      if (data.html != "") {
              //          $("#div_series_cusubject").html(unescape(data.html));
              //      }
               // });
            }
        }


    }
}
Pui.showData = function (json) {
    var path = {
        user: ['.t_login span', '.c_friend span', '.c_fans span', '.c_view span', '.c_video span', '.c_flower span'],
        video: ['.c_view span', '.c_review span', '.c_bookmark span'],
        special: ['.c_video span', '.c_view span', '.c_rss span', '.t_update span', '.t_length span'],
        combo: ['.d_video span', '.d_collect span', '.d_topic span', '.d_menber span', '.d_album span', '.d_mvvideo span'],
        combo_handle: ['.c_num', '.c_num_m']
    };
    var path_n = {
        user: ['.d_time_login span', '.d_friend span', '.d_fans span', '.d_view span', '.d_video span', '.d_flower span'],
        video: ['.d_view span', '.d_review span', '.d_bookmark span'],
        special: ['.d_video span', '.d_view span', '.d_rss span', '.d_update span', '.d_length span'],
        combo: ['.d_video span', '.d_collect span', '.d_topic span', '.d_menber span', '.d_album span', '.d_mvvideo span']
    };
    var path_c = {
        video: ['.pop']
    };
    $('.t_login').html('最近登录：<span></span>');
    for (var i = 0,
    length = json.length; i < length; i++) {
        var type = json[i].type,
        id = json[i].id,
        data = json[i].data,
        wrap = '#' + type + '_' + id;
        if (!$(wrap)[0]) continue;
        for (j = 0; j < path[type].length; j++) {
            if ($(wrap + ' ' + path[type][j])[0]) {
                $(wrap + ' ' + path[type][j])[0].innerHTML = data[j];
            } else if ($(wrap + ' ' + path_n[type][j])[0]) {
                $(wrap + ' ' + path_n[type][j])[0].innerHTML = data[j];
            } else if ($(wrap + ' ' + path_c[type][j])[0]) {
                $(wrap + ' ' + path_c[type][j])[0].innerHTML = data[j];
            }
        }
    }
};
String.prototype.strLen = function (lim) {
    var self_lim = lim,
    len = 0;
    for (var i = 0,
    l = this.length; i < l; i++) {
        if (this.charCodeAt(i) > 255 || this.charCodeAt(i) < 0) {
            len += 2;
            if (len <= self_lim) lim -= 1;
            else break;
        } else len += 1;
    }
    if (len <= lim) {
        return this.toString();
    } else {
        return this.slice(0, Math.floor(lim)) + '...';
    }
}
Pui.widget = {
	/*公用部件--video/img/blog频道页轮播*/
	focusTurn: function (sAct, oData) {
        var i = 0, f = $('.picshow'), l = f.find('.current_pic .focus').length, s = '';
        function num() {
            for (var j = 0; j < l; j++) {
                s += '<a href="" title="第' + (j + 1) + '张">' + (j + 1) + '</a>';
            }
            num_w = 28 * l;
            f.find('.num').append(s).width(num_w).find('a').removeClass('ac').hover(function () {
                clearTimeout(t);
                var _self = $(this);
                _self.addClass('ac');
                i = f.find('.num a').index(_self[0]);
                g(sAct, oData);
				clearTimeout(t);
                return false;
            }, function () { t=setTimeout(function () { g(sAct, oData) }, oData.timer); }).click(function () { return false; });
			$('.current_pic').hover(function(){clearTimeout(t);},function (){t=setTimeout(function () { g(sAct, oData) }, oData.timer);});
			 showThumb();
        }
        function g(sAct, oData) {
            f.find('.num a').removeClass('ac');
            if (i < l) {
                switch (sAct) {
                    case 'slide':
                        f.find('.thumb_bg').animate({ left: -367 * i }, 300);
                        f.find('.current_pic .row').animate({ left: oData.distance * i }, oData.speed);
                }
                f.find('.num a:eq(' + i + ')').addClass('ac');
                Pui.autoThumb('.picshow .current_pic .focus:eq(' + i + ') img', oData.width, oData.height);
                i++;
                t = setTimeout(function () { g(sAct, oData) }, oData.timer);
            }
            else { i = 0; g(sAct, oData); }
        }
        function showThumb() {
            var ct = f.find('.current_pic .focus img');
            s = '';
            for (var j = 0; j < l; j++) {
                var now = f.find('.current_pic .focus img').eq(j).attr('src');
                s += '<div class="thumb"><a href=""><img src="' + now + '" alt="" /></a></div>';

            }
            s = '<div class="thumb"><a href=""><img src="' + ct.eq(l - 1).attr('src') + '" alt="" /></a></div>' + s;
            s += '<div class="thumb"><a href=""><img src="' + ct.eq(0).attr('src') + '" alt="" /></a></div>';
            f.find('.thumb_bg').append(s).width(735 * (l + 1)).find('a').click(function () {
                clearTimeout(t);
                var _self = $(this);
                i = f.find('.thumb_bg a').index(_self[0]) - 1;
                if (i < 0) i = l - 1;
                g();
                return false;

            });
        }
        if (l) { f.find('.current_pic .row').width(oData.width * (l + 1)); num(); g(sAct, oData); }
    }
}
Pui.Site = {
	init:function(){
	     Pui.widget.focusTurn('slide',{'mode':'simple','distance':-667,'width':662,'height':330,'speed':300,'timer':3000});
		 Pui.newHeader.init();
	}
}
Pui.newHeader = {
	init:function(){
	$('#SearchForm').submit(function () {
            Pui.newHeader.DoSearch(this);
            return false;
         });
	this.ChangeItem();
	},
	DoSearch: function (o) {
        var val = $(o).find('#SearchInput').val();

		var thisBody = $('body');
		var url;

        if ($.trim(val) == '' || val == '搜一下') {
            alert('对不起，关键词不能为空，请重新输入');
            $('#SearchInput').focus();
            return false;
        } else {
            var sdi = o.searchDomain;
            var sd = "http://so.baomihua.com";
            if (sdi != undefined && sdi.value != "") {
                sd = sdi.value;
            }
            var key = val;
			if (thisBody.hasClass('bBlog')||thisBody.hasClass('soBlog')){
                url = sd + "/b/" + key + '.html';
			}else if(thisBody.hasClass('bImg')||thisBody.hasClass('soPic')){
				url = sd + "/img/" + key + '.html';
			}else
			{
			    url = sd + "/v/" + key + '_p0s04.html';
			}

            if (document.location.hostname.indexOf("so.baomihua.com") != -1) {
                document.location.href = url;
            } else {
                window.open(url, 'search');
            }
            return false;
			}
    },
	ChangeItem:function(){
	    var thisBody = $('body');
		var yuanj = $('<b class="lt"></b><b class="rt"></b>');
		if (thisBody.hasClass('bBlog')||thisBody.hasClass('soBlog')){
			$('#Item .sBlog').addClass('ac').append(yuanj);
			$('#Item a').not('.sBlog').removeClass('ac');
		}else if(thisBody.hasClass('bImg')||thisBody.hasClass('soPic')){
		   $('#Item .sPic').addClass('ac').append(yuanj);
		   $('#Item a').not('.sPic').removeClass('ac');
		}else
		{
		   $('#Item .sVideo').addClass('ac').append(yuanj);
		   $('#Item a').not('.sVideo').removeClass('ac');
		 };
	}
}

function sKeyWord(){
	var sInput = document.getElementById("SearchInput");
	sInput.value = SEARCH_KEYWORD;
	sInput.onfocus = function(){
	    if (this.value == SEARCH_KEYWORD) {
			this.value = "";
		}
	}
	sInput.onblur = function(){
		if(this.value == ""){
		    this.value = SEARCH_KEYWORD;
		}
	}
}
if (typeof (SEARCH_KEYWORD) != "undefined" && document.getElementById("SearchInput")) {
	sKeyWord();
}

$('.ad_common').each(function() {
	var txt = $(this).html();
	if($.trim(txt) == ""){$(this).css("marginBottom","0px");}
});